<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/9/17 0017
 * Time: 下午 9:04
 */

namespace Home\Controller;


use Think\Controller;

class CheckController extends Controller
{
    protected function _initialize()
    {
        session('openid','oGlnPvnJNzlUlXQj5ywvvkIW1Jhk');
        if (!session('openid')) {
            $treemember = M('treemember');
            $appid= C('appid');
            $secret = C('secret');
            $code = $_GET['code'];
            $type = $_GET['type'];
            $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code";
            $a = file_get_contents($url);
            $arr = json_decode($a,true);
            $openid = $arr['openid'];
            /**测试使用正式上线删除**/
            $res = $treemember->where("openid_1='$openid' or openid_2='$openid' or openid_3='$openid'")->find();
            session('openid',$openid);
            if ($res === null || $openid === null) {
                $this->redirect('Bind/index');
            }
        }
    }
}